package top.myhdg.bijou.part;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;

//==========可设置最大高度的ListView==========
public class MaxHListView extends ListView {
    private int listViewHeight;

    public MaxHListView(Context context) {
        super(context);
    }

    public MaxHListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MaxHListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setListViewHeight(int listViewHeight) {
        this.listViewHeight = listViewHeight;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(listViewHeight, MeasureSpec.AT_MOST);

        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    //=====dp转化为px=====
    public static int dpToPx(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale+0.5f);
    }
    //=====dp转化为px=====
}
//==========可设置最大高度的ListView==========
